package edu.suda.xsap.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/*************************
 * 此类用来封装返回给前端的数据
 */
@Data
@AllArgsConstructor
@Builder
public class Result {
    private int code; //状态码
    private String message; //提示信息
    private Object data; //数据

    public static Result success(){
        return success(null);
    }
    public static Result success(Object data){
        return Result.builder()
                        .code(200)
                        .message("success")
                        .data(data)
                        .build();
    }

    public static Result success(String message, Object data){
        return Result.builder()
                .code(200)
                .message(message)
                .data(data)
                .build();
    }

    public static Result failure(){
        return failure(null);
    }
    public static Result failure(Object data){
        return Result.builder()
                .code(500)
                .message("failure")
                .data(data)
                .build();
    }
    public static Result failure(String message,Object data){
        return Result.builder()
                .code(500)
                .message(message)
                .data(data)
                .build();
    }
}
